package com.atguigu.eduservice.controller.front;

import com.atguigu.commonutil.R;
import com.atguigu.eduservice.entity.EduCourse;
import com.atguigu.eduservice.entity.Teacher;
import com.atguigu.eduservice.service.EduCourseService;
import com.atguigu.eduservice.service.TeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.lettuce.core.Limit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/eduservice/teacherfront")
public class TeacherFrontController {

    @Autowired
    private TeacherService teacherService;

    @Autowired
    private EduCourseService eduCourseService;

    @GetMapping("/getTeacherFrontList/{page}/{limit}")
    public R getTeacherFrontList(@PathVariable Long page,
                                 @PathVariable Long limit) {
        Page<Teacher> pageParam = new Page<>(page, limit);
        Map<String, Object> map = teacherService.getTeacherFrontList(pageParam);

        return R.ok().data(map);
    }


    //2.讲师详情的功能
    @GetMapping("getTeacherFrontInfo/{teacherId}")
    public R getTeacherFrontInfo(@PathVariable String teacherId) {
        //1.根据讲师id查询讲师基本信息
        Teacher eduTeacher = teacherService.getById(teacherId);
        //2.根据讲师id查询所有课程
        QueryWrapper<EduCourse> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("teacher_id", teacherId);
        List<EduCourse> courseList = eduCourseService.list(queryWrapper);

        return R.ok().data("teacher", eduTeacher).data("courseList", courseList);
    }

}
